class Shape implements IMovable, IFollowable
{
  private Vector2 pos;
  private IMovementStrategy movementStrategy;
  private Polonaise polonaise;
  
  public Shape(Vector2 initialPos, Polonaise polonaise)
  {
    this.polonaise = polonaise;
    this.pos = initialPos;
  }
  
  public void setMovementStrategy(IMovementStrategy value)
  {
    this.movementStrategy = value;
  }
  
  public void update()
  {
    if (this.movementStrategy instanceof FollowingMovementStrategy && this.pos.y < 100)
    {
      this.polonaise.detach(this);
      this.movementStrategy = new FallingMovementStrategy(this);
    }
    else if (this.movementStrategy instanceof FallingMovementStrategy && this.pos.y > 400)
    {
      this.movementStrategy = new WalkingMovementStrategy(this);
    }
    else if (this.movementStrategy instanceof WalkingMovementStrategy && (this.pos.x < 50 || this.pos.x > 590))
    {
      this.polonaise.attach(this);
    } 
    if (this.movementStrategy != null)
    {
      this.movementStrategy.move();
    }
  }
  
  public Vector2 getPos()
  {
    return this.pos;
  }
  
  public void setPos(Vector2 value)
  {
    this.pos = value;
  }
  
  public void drawShape()
  {
    ellipse(pos.x, pos.y, 30, 30);
  }
}
